package com.autonavi.yunda.yunji.service;

import com.autonavi.yunda.yunji.core.service.IInterfaceConfigService;
import com.autonavi.yunda.yunji.core.vo.EngineInterfaceConfigVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author cizhong.wcs
 * @date 2023/8/31 10:44
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class InterfaceConfigService implements IInterfaceConfigService {

    @Override
    public EngineInterfaceConfigVO fetchCurrentValidScriptVO(String uri) {
        return FileLoaderService.interfaceConfigVOS.stream()
                .filter(vo -> vo.getUri().equals(uri))
                .findFirst().orElse(null);
    }

    @Override
    public List<String> listNewPublishedUris(Collection<String> existsUris) {
        return FileLoaderService.interfaceConfigVOS.stream()
                .map(EngineInterfaceConfigVO::getUri)
                .filter(uri -> !existsUris.contains(uri))
                .collect(Collectors.toList());
    }

}
